<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .mask {
            position: fixed;
            left: 0;
            top: 0;
            width: 100vw;
            height: 100vh;
            background: #000;
            transition: all .3s;
        }
    </style>
</head>

<body>
    <div id="mask"></div>
</body>
<script>
    function usePreventScreenShot(cb) {
        window.onkeydown = function (e) {
            if (e.key === 'Control') {
                window.onkeydown = function (e) {
                    if (e.key === 'Alt') {
                        cb()
                    }
                }
            }
        }
    }
</script>
<script>
    window.onload = function () {
        const mask = document.getElementById('mask')
        console.log(mask)

        usePreventScreenShot(function () {
            mask.classList.add('mask')
            if (confirm('不允许截图')) {
                console.log(true)
            } else {
                mask.classList.remove('mask')
            }
        })
    }
</script>

</html>